package com.dmxtechnologies.community.war.page;


import java.io.IOException;

import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletResponse;

import com.dmxtechnologies.community.ejb.interfaces.JWHIndexTimeBroadcastRemote;
import com.dmxtechnologies.community.war.CMSJWHAccessBean;

@Named("cmsPageBean")
@SessionScoped
@Singleton
public class CMSPageBean {
	
	private int count=1;
	
	@EJB
	JWHIndexTimeBroadcastRemote jwhIndexTimeBroadcastRemote;
	
	@Inject
	CMSJWHAccessBean cmsjwhAccessBean;
	
	public void nowPage() throws Exception{
		jwhIndexTimeBroadcastRemote.getJWHIndexListInPageNum(Integer.valueOf(2));
	}
   
	public String trunNext() throws Exception{
		count++;
		if(count > cmsjwhAccessBean.getBaseResponse().getTotalPage()){
			count = cmsjwhAccessBean.getBaseResponse().getTotalPage();
		}
		jwhIndexTimeBroadcastRemote.getJWHIndexListInPageNum(count);
//		redirect();
		return null;
	}

	private void redirect() throws IOException {
		FacesContext fc = FacesContext.getCurrentInstance();
		HttpServletResponse response = (HttpServletResponse) fc
				.getExternalContext().getResponse();
		String url = fc.getExternalContext()
				.getRequestContextPath() + "/faces/juweihui_home.xhtml";
		response.sendRedirect(url);
		fc.renderResponse();
	}
	
	public String trunPre() throws Exception{
		count--;
		if(count < 1){
			count = 1;
		}
		jwhIndexTimeBroadcastRemote.getJWHIndexListInPageNum(count);
//		redirect();
		return null;
	}
}
